
var map;
var markersArray = [];
google.maps.event.addDomListener(window, 'load', initialize);
console.log('Javascript from file OK');


function initialize() {
    
    var myLatlng = new google.maps.LatLng(55.750089,52.601591);
    var mapOptions = {
    zoom: 4,
    center: myLatlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    map = new google.maps.Map(document.getElementById('map_canvas'),
                              mapOptions);
    
//    var marker = new google.maps.Marker({
//                                        position: myLatlng,
//                                        map: map,
//                                        title: 'Hello World!'
//                                        });
};

function showAllPins() {
    
    if(!db){
        db = openDatabase("dbMap", "0.1", "A list of points.", 200000);
        console.log('Data Base open connection');
        if(!db){
            alert("Failed to connect to database.");
        }
    }else{console.log('Data Base was find');}
    
    db.transaction(function(tx) {
                   tx.executeSql("SELECT * FROM mPins", [],
                                 function(tx, result) {
                                    for(var i = 0; i < result.rows.length; i++) {
                                       var row = result.rows.item(i)
                                       //add new pin
                                        console.log(row['address']+row['ident']);
                                        var myLatlng = new google.maps.LatLng(row['lat'],row['longt']);
                                        var marker = new google.maps.Marker({
                                                                     position: myLatlng,
                                                                     icon:'pin1-1.png',
                                                                     map: map,
                                                                     title: row['address']
                                                                     });
                                        markersArray.push(marker);
                                        google.maps.event.addListener(marker,"click",function(){
                                                                      console.log("click on marker");
                                                                      });
                                    }
                                 }, function (tx, error) {
                                 console.log(error);
                                 })});
};